﻿#include "FITKAbaqusHDF5AdaptorConnectorSection.h"
#include "FITKAbaqusHDF5AdaptorConnectorBehavior.h"
#include "FITK_Kernel/FITKCore/FITKEnumTransformer.hpp"
#include "FITK_Interface/FITKInterfaceIO/FITKAbstractHDF5Reader.h"
#include "FITK_Interface/FITKInterfaceIO/FITKAbstractHDF5Writer.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaConnectorAssignment.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaConnectorBehavior.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaConnectorSection.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaConnectorBehaviorElasticity.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaConnectorBehaviorPlasticity.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaConnectorBehaviorDamping.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaConnectorBehaviorLock.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaConnectorBehaviorStop.h"

namespace IO
{
    QString FITKAbaqusHDF5AdaptorConnectorSection::getAdaptorClass()
    {
        return "FITKAbaqusHDF5AdaptorConnectorSection";
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::adaptR()
    {
        auto connectorSection = dynamic_cast<Interface::FITKAbaConnectorSection*>(_dataObj);
        if (!_reader || !connectorSection || !_h5Group) return false;
        bool isR = true;
        isR &= readConnectorSection(connectorSection, *_h5Group);
        return isR;
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::adaptW()
    {
        auto connectorSection = dynamic_cast<Interface::FITKAbaConnectorSection*>(_dataObj);
        if (!_writer || !connectorSection || !_h5Group) return false;
        bool isW = true;
        isW &= writeConnectorSection(connectorSection, *_h5Group);
        return isW;
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::readConnectorSection(Interface::FITKAbaConnectorSection * connectorSection, H5::Group & h5Group)
    {
        if (!connectorSection) return false;
        bool isValid = false;
        QString name = connectorSection->getDataObjectName();
        //写出基础数据
        bool isR = readNDataObject(connectorSection, h5Group);
        if (!isR) return false;

        //类型
        auto sCategory = readStrAttribute(h5Group, "Category");
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorSection::Category> fitkTypeTrafer;
        auto eCategory = fitkTypeTrafer.fromString(QString::fromStdString(sCategory), isValid);
        if (!isValid) return false;
        connectorSection->setCategory(eCategory);

        //组装的复杂类型
        auto sAssembledComplexType = readStrAttribute(h5Group, "AssembledComplexType");
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorSection::AssembledComplexType> fitkCTTypeTrafer;
        auto eAssembledComplexType = fitkCTTypeTrafer.fromString(QString::fromStdString(sAssembledComplexType), isValid);
        if (!isValid) return false;
        connectorSection->setAssebledComplexType(eAssembledComplexType);

        //翻译类型
        auto sTranslationalType = readStrAttribute(h5Group, "TranslationalType");
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorSection::TranslationalType> fitkTTTypeTrafer;
        auto eTranslationalType = fitkTTTypeTrafer.fromString(QString::fromStdString(sTranslationalType), isValid);
        if (!isValid) return false;
        connectorSection->setTranslationalType(eTranslationalType);

        //旋转类型
        auto sRotationalType = readStrAttribute(h5Group, "RotationalType");
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorSection::RotationalType> fitkRTypeTrafer;
        auto eRotationalType = fitkRTypeTrafer.fromString(QString::fromStdString(sRotationalType), isValid);
        if (!isValid) return false;
        connectorSection->setRotationalType(eRotationalType);


        int BehaviorCount = readIntAttribute(h5Group, "BehaviorCount");
        for (int i = 0; i < BehaviorCount; ++i)
        {
            auto behaviorGroup = h5Group.openGroup("behavior_" + std::to_string(i));

            //类型
            Interface::FITKAbaConnectorBehavior* behavior{};
            auto sBehaviorType = readStrAttribute(behaviorGroup, "BehaviorType");
            if (sBehaviorType == "Elasticity")
                behavior = new Interface::FITKAbaConnectorBehaviorElasticity();
            else if (sBehaviorType == "Plasticity")
                behavior = new Interface::FITKAbaConnectorBehaviorPlasticity();
            else if (sBehaviorType == "Damping")
                behavior = new Interface::FITKAbaConnectorBehaviorDamping();
            else if (sBehaviorType == "Stop")
                behavior = new Interface::FITKAbaConnectorBehaviorStop();
            else if (sBehaviorType == "Lock")
                behavior = new Interface::FITKAbaConnectorBehaviorLock();
            if (!behavior) return false;

            connectorSection->addBehavior(behavior);
            isR &= readConnectorAssignment(behavior, behaviorGroup);
        }
        return isR;
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::writeConnectorSection(Interface::FITKAbaConnectorSection * connectorSection, H5::Group & h5Group)
    {
        if (!connectorSection) return false;
        bool isValid = false;

        auto groupName = createParentAttribute(connectorSection, h5Group);
        auto connectorSectionGroup = h5Group.createGroup(groupName);
        //写出基础数据
        bool isW = writeNDataObject(connectorSection, connectorSectionGroup);
        if (!isW) return false;

        //类型
        auto eCategory = connectorSection->getCategory();
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorSection::Category> fitkTypeTrafer;
        QString sCategory = fitkTypeTrafer.toStrting(eCategory, isValid);
        if (!isValid) return false;
        writeStrAttribute(connectorSectionGroup, "Category", sCategory.toStdString());

        //组装的复杂类型
        auto eAssembledComplexType = connectorSection->getAssembledComplexType();
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorSection::AssembledComplexType> fitkCTTypeTrafer;
        QString sAssembledComplexType = fitkCTTypeTrafer.toStrting(eAssembledComplexType, isValid);
        if (!isValid) return false;
        writeStrAttribute(connectorSectionGroup, "AssembledComplexType", sAssembledComplexType.toStdString());

        //翻译类型
        auto eTranslationalType = connectorSection->getTranslationalType();
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorSection::TranslationalType> fitkTTTypeTrafer;
        QString sTranslationalType = fitkTTTypeTrafer.toStrting(eTranslationalType, isValid);
        if (!isValid) return false;
        writeStrAttribute(connectorSectionGroup, "TranslationalType", sTranslationalType.toStdString());

        //旋转类型
        auto eRotationalType = connectorSection->getRotationalType();
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorSection::RotationalType> fitkRTypeTrafer;
        QString sRotationalType = fitkRTypeTrafer.toStrting(eRotationalType, isValid);
        if (!isValid) return false;
        writeStrAttribute(connectorSectionGroup, "RotationalType", sRotationalType.toStdString());

        int behaviorCount = connectorSection->getAllBehaviors().size();
        writeIntAttribute(connectorSectionGroup, "BehaviorCount", &behaviorCount);

        for (int i = 0; i < behaviorCount; ++i)
        {
            auto behaviorGroup = connectorSectionGroup.createGroup("behavior_" + std::to_string(i));
            Interface::FITKAbaConnectorBehavior* behavior = connectorSection->getAllBehaviors()[i];
            isW &= writeConnectorAssignment(behavior, behaviorGroup);
        }
        return isW;
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::readConnectorAssignment(Interface::FITKAbaConnectorBehavior * connectorBehavior, H5::Group & h5Group)
    {
        if (!connectorBehavior) return false;
        auto eType = connectorBehavior->getBehaviorType();

        if (eType == Interface::FITKAbaConnectorBehaviorEnum::ConnectorBehaviorType::Damping)
            return readBehaviorDamping(connectorBehavior, h5Group);
        else  if (eType == Interface::FITKAbaConnectorBehaviorEnum::ConnectorBehaviorType::Elasticity)
            return readBehaviorElasticity(connectorBehavior, h5Group);
        else  if (eType == Interface::FITKAbaConnectorBehaviorEnum::ConnectorBehaviorType::Lock)
            return readBehaviorLock(connectorBehavior, h5Group);
        else  if (eType == Interface::FITKAbaConnectorBehaviorEnum::ConnectorBehaviorType::Plasticity)
            return readBehaviorPlasticity(connectorBehavior, h5Group);
        else  if (eType == Interface::FITKAbaConnectorBehaviorEnum::ConnectorBehaviorType::Stop)
            return readBehaviorStop(connectorBehavior, h5Group);
        return false;
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::writeConnectorAssignment(Interface::FITKAbaConnectorBehavior * connectorBehavior, H5::Group & h5Group)
    {
        if (!connectorBehavior) return false;
        bool isValid = false;
        auto eBehaviorType = connectorBehavior->getBehaviorType();

        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::ConnectorBehaviorType> fitkTypeTrafer;
        QString sBehaviorType = fitkTypeTrafer.toStrting(eBehaviorType, isValid);
        if (!isValid) return false;
        writeStrAttribute(h5Group, "BehaviorType", sBehaviorType.toStdString());

        if (eBehaviorType == Interface::FITKAbaConnectorBehaviorEnum::ConnectorBehaviorType::Damping)
            return writeBehaviorDamping(connectorBehavior, h5Group);
        else  if (eBehaviorType == Interface::FITKAbaConnectorBehaviorEnum::ConnectorBehaviorType::Elasticity)
            return writeBehaviorElasticity(connectorBehavior, h5Group);
        else  if (eBehaviorType == Interface::FITKAbaConnectorBehaviorEnum::ConnectorBehaviorType::Lock)
            return writeBehaviorLock(connectorBehavior, h5Group);
        else  if (eBehaviorType == Interface::FITKAbaConnectorBehaviorEnum::ConnectorBehaviorType::Plasticity)
            return writeBehaviorPlasticity(connectorBehavior, h5Group);
        else  if (eBehaviorType == Interface::FITKAbaConnectorBehaviorEnum::ConnectorBehaviorType::Stop)
            return writeBehaviorStop(connectorBehavior, h5Group);
        return false;
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::readBehaviorElasticity(Interface::FITKAbaConnectorBehavior* connectorBehavior, H5::Group & h5Group)
    {
        auto cb = dynamic_cast<Interface::FITKAbaConnectorBehaviorElasticity*>(connectorBehavior);
        if (!cb) return false;
        bool isValid = false;


        if (h5Group.attrExists("ForceMomentStates"))
        {
            H5::Attribute att = h5Group.openAttribute("ForceMomentStates");
            std::array<bool, 6> buf;
            att.read(H5::PredType::NATIVE_HBOOL, &buf);
            cb->setForceMomentStates(buf);
        }

        auto sDefinition = readStrAttribute(h5Group, "Definition");
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::Definition> fitkDTypeTrafer;
        auto eDefinition = fitkDTypeTrafer.fromString(QString::fromStdString(sDefinition), isValid);
        if (!isValid) return false;
        cb->setDefinition(eDefinition);

        auto sCoupling = readStrAttribute(h5Group, "Coupling");
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::Coupling> fitkCTypeTrafer;
        auto eCoupling = fitkCTypeTrafer.fromString(QString::fromStdString(sCoupling), isValid);
        if (!isValid) return false;
        cb->setCoupling(eCoupling);

        if (h5Group.attrExists("ComponentsStates"))
        {
            H5::Attribute att = h5Group.openAttribute("ComponentsStates");
            std::array<bool, 6> buf;
            att.read(H5::PredType::NATIVE_HBOOL, &buf);
            cb->setComponentsStates(buf);
        }

        if (h5Group.attrExists("IndepenentComponents"))
        {
            H5::Attribute att = h5Group.openAttribute("IndepenentComponents");
            std::array<bool, 6> buf;
            att.read(H5::PredType::NATIVE_HBOOL, &buf);
            cb->setIndependentComponents(buf);
        }

        int dataRowCount = readIntAttribute(h5Group, "DataRowCount");
        cb->setDataRowCount(dataRowCount);
        for (int i = 0; i < dataRowCount; ++i)
        {
            Interface::ConnectorBHElasticityData& data = cb->getRowData(i);
            QList<double> dataList;
            if (readDoubleAttrbuteDataSet(h5Group, std::to_string(i), dataList, 1, 41))
            {
                data.setD11(dataList[0]);
                data.setD12(dataList[1]);
                data.setD22(dataList[2]);
                data.setD13(dataList[3]);
                data.setD23(dataList[4]);
                data.setD33(dataList[5]);
                data.setD14(dataList[6]);
                data.setD24(dataList[7]);
                data.setD34(dataList[8]);
                data.setD44(dataList[9]);
                data.setD15(dataList[10]);
                data.setD25(dataList[11]);
                data.setD35(dataList[12]);
                data.setD45(dataList[13]);
                data.setD55(dataList[14]);
                data.setD16(dataList[15]);
                data.setD26(dataList[16]);
                data.setD36(dataList[17]);
                data.setD46(dataList[18]);
                data.setD56(dataList[19]);
                data.setD66(dataList[20]);
                data.setForM(dataList[21]);
                data.setUorUR(dataList[22]);
                data.setF1(dataList[23]);
                data.setF2(dataList[24]);
                data.setF3(dataList[25]);
                data.setM1(dataList[26]);
                data.setM2(dataList[27]);
                data.setM3(dataList[28]);
                data.setCP1(dataList[29]);
                data.setCP2(dataList[30]);
                data.setCP3(dataList[31]);
                data.setCPR1(dataList[32]);
                data.setCPR2(dataList[33]);
                data.setCPR3(dataList[34]);
                data.setCCU1(dataList[35]);
                data.setCCU2(dataList[36]);
                data.setCCU3(dataList[37]);
                data.setCCUR1(dataList[38]);
                data.setCCUR2(dataList[39]);
                data.setCCUR3(dataList[40]);
            }
        }
        return true;
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::writeBehaviorElasticity(Interface::FITKAbaConnectorBehavior* connectorBehavior, H5::Group & h5Group)
    {
        auto cb = dynamic_cast<Interface::FITKAbaConnectorBehaviorElasticity*>(connectorBehavior);
        if (!cb) return false;
        bool isValid = false;
        auto forceMoment = cb->getForceMomentStates();
        writeBoolAttribute(h5Group, "ForceMomentStates", &forceMoment, 1, 6);

        auto eDefinition = cb->getDefinition();
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::Definition> fitkDTypeTrafer;
        QString sDefinition = fitkDTypeTrafer.toStrting(eDefinition, isValid);
        if (!isValid) return false;
        writeStrAttribute(h5Group, "Definition", sDefinition.toStdString());

        auto eCoupling = cb->getCoupling();
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::Coupling> fitkCTypeTrafer;
        QString sCoupling = fitkCTypeTrafer.toStrting(eCoupling, isValid);
        if (!isValid) return false;
        writeStrAttribute(h5Group, "Coupling", sCoupling.toStdString());

        auto componentsStates = cb->getComponentsStates();
        writeBoolAttribute(h5Group, "ComponentsStates", &componentsStates, 1, 6);

        auto indepenentComponents = cb->getIndepenentComponents();
        writeBoolAttribute(h5Group, "IndepenentComponents", &indepenentComponents, 1, 6);
        int dataRowCount = cb->getDataRowCount();
        writeIntAttribute(h5Group, "DataRowCount", &dataRowCount);

        for (int i = 0; i < dataRowCount; ++i)
        {
            Interface::ConnectorBHElasticityData& data = cb->getRowData(i);
            QList<double> dataList;
            dataList.append(data.getD11());
            dataList.append(data.getD12());
            dataList.append(data.getD22());
            dataList.append(data.getD13());
            dataList.append(data.getD23());
            dataList.append(data.getD33());
            dataList.append(data.getD14());
            dataList.append(data.getD24());
            dataList.append(data.getD34());
            dataList.append(data.getD44());
            dataList.append(data.getD15());
            dataList.append(data.getD25());
            dataList.append(data.getD35());
            dataList.append(data.getD45());
            dataList.append(data.getD55());
            dataList.append(data.getD16());
            dataList.append(data.getD26());
            dataList.append(data.getD36());
            dataList.append(data.getD46());
            dataList.append(data.getD56());
            dataList.append(data.getD66());
            dataList.append(data.getForM());
            dataList.append(data.getUorUR());
            dataList.append(data.getF1());
            dataList.append(data.getF2());
            dataList.append(data.getF3());
            dataList.append(data.getM1());
            dataList.append(data.getM2());
            dataList.append(data.getM3());
            dataList.append(data.getCP1());
            dataList.append(data.getCP2());
            dataList.append(data.getCP3());
            dataList.append(data.getCPR1());
            dataList.append(data.getCPR2());
            dataList.append(data.getCPR3());
            dataList.append(data.getCCU1());
            dataList.append(data.getCCU2());
            dataList.append(data.getCCU3());
            dataList.append(data.getCCUR1());
            dataList.append(data.getCCUR2());
            dataList.append(data.getCCUR3());
            writeDoubleAttributeDataset(h5Group, std::to_string(i), dataList, 1, 41);
        }
        return true;
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::readBehaviorDamping(Interface::FITKAbaConnectorBehavior * connectorBehavior, H5::Group & h5Group)
    {
        auto cb = dynamic_cast<Interface::FITKAbaConnectorBehaviorDamping*>(connectorBehavior);
        if (!cb) return false;
        bool isValid = false;

        if (h5Group.attrExists("ForceMoment"))
        {
            H5::Attribute att = h5Group.openAttribute("ForceMoment");
            std::array<bool, 6> buf;
            att.read(H5::PredType::NATIVE_HBOOL, &buf);
            cb->setForceMoment(buf);
        }
        auto sDefinition = readStrAttribute(h5Group, "Definition");
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::Definition> fitkDTypeTrafer;
        auto eDefinition = fitkDTypeTrafer.fromString(QString::fromStdString(sDefinition), isValid);
        if (!isValid) return false;
        cb->setDefinition(eDefinition);

        auto sCoupling = readStrAttribute(h5Group, "Coupling");
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::Coupling> fitkCTypeTrafer;
        auto eCoupling = fitkCTypeTrafer.fromString(QString::fromStdString(sCoupling), isValid);
        if (!isValid) return false;
        cb->setCoupling(eCoupling);

        if (h5Group.attrExists("IndependentComps"))
        {
            H5::Attribute att = h5Group.openAttribute("IndependentComps");
            std::array<bool, 6> buf;
            att.read(H5::PredType::NATIVE_HBOOL, &buf);
            cb->setIndependentComps(buf);
        }

        int dataRowCount = readIntAttribute(h5Group, "DataRowCount");
        cb->setDataRowCount(dataRowCount);
        for (int i = 0; i < dataRowCount; ++i)
        {
            Interface::ConnectorBHDampingData& data = cb->getRowData(i);
            QList<double> dataList;

            if (readDoubleAttrbuteDataSet(h5Group, std::to_string(i), dataList, 1, 47))
            {
                data.setC11(dataList[0]);
                data.setC12(dataList[1]);
                data.setC22(dataList[2]);
                data.setC13(dataList[3]);
                data.setC23(dataList[4]);
                data.setC33(dataList[5]);
                data.setC14(dataList[6]);
                data.setC24(dataList[7]);
                data.setC34(dataList[8]);
                data.setC44(dataList[9]);
                data.setC15(dataList[10]);
                data.setC25(dataList[11]);
                data.setC35(dataList[12]);
                data.setC45(dataList[13]);
                data.setC55(dataList[14]);
                data.setC16(dataList[15]);
                data.setC26(dataList[16]);
                data.setC36(dataList[17]);
                data.setC46(dataList[18]);
                data.setC56(dataList[19]);
                data.setC66(dataList[20]);
                data.setForM(dataList[21]);
                data.setVorVR(dataList[22]);
                data.setF1(dataList[23]);
                data.setF2(dataList[24]);
                data.setF3(dataList[25]);
                data.setM1(dataList[26]);
                data.setM2(dataList[27]);
                data.setM3(dataList[28]);
                data.setV1(dataList[29]);
                data.setV2(dataList[30]);
                data.setV3(dataList[31]);
                data.setVR1(dataList[32]);
                data.setVR2(dataList[33]);
                data.setVR3(dataList[34]);
                data.setCP1(dataList[35]);
                data.setCP2(dataList[36]);
                data.setCP3(dataList[37]);
                data.setCPR1(dataList[38]);
                data.setCPR2(dataList[39]);
                data.setCPR3(dataList[40]);
                data.setCCU1(dataList[41]);
                data.setCCU2(dataList[42]);
                data.setCCU3(dataList[43]);
                data.setCCUR1(dataList[44]);
                data.setCCUR2(dataList[45]);
                data.setCCUR3(dataList[46]);
            }
        }
        return true;
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::writeBehaviorDamping(Interface::FITKAbaConnectorBehavior * connectorBehavior, H5::Group & h5Group)
    {
        auto cb = dynamic_cast<Interface::FITKAbaConnectorBehaviorDamping*>(connectorBehavior);
        if (!cb) return false;
        bool isValid = false;

        auto forceMoment = cb->getForceMoment();
        writeBoolAttribute(h5Group, "ForceMoment", &forceMoment, 1, 6);

        auto eDefinition = cb->getDefinition();
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::Definition> fitkDTypeTrafer;
        QString sDefinition = fitkDTypeTrafer.toStrting(eDefinition, isValid);
        if (!isValid) return false;
        writeStrAttribute(h5Group, "Definition", sDefinition.toStdString());

        auto independentComps = cb->getIndependentComps();
        writeBoolAttribute(h5Group, "IndependentComps", &independentComps, 1, 6);

        auto eCoupling = cb->getCoupling();
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::Coupling> fitkCTypeTrafer;
        QString sCoupling = fitkCTypeTrafer.toStrting(eCoupling, isValid);
        if (!isValid) return false;
        writeStrAttribute(h5Group, "Coupling", sCoupling.toStdString());

        int dataRowCount = cb->getDataRowCount();
        writeIntAttribute(h5Group, "DataRowCount", &dataRowCount);
        for (int i = 0; i < dataRowCount; ++i)
        {
            Interface::ConnectorBHDampingData& data = cb->getRowData(i);
            QList<double> dataList;
            dataList.append(data.getC11());
            dataList.append(data.getC12());
            dataList.append(data.getC22());
            dataList.append(data.getC13());
            dataList.append(data.getC23());
            dataList.append(data.getC33());
            dataList.append(data.getC14());
            dataList.append(data.getC24());
            dataList.append(data.getC34());
            dataList.append(data.getC44());
            dataList.append(data.getC15());
            dataList.append(data.getC25());
            dataList.append(data.getC35());
            dataList.append(data.getC45());
            dataList.append(data.getC55());
            dataList.append(data.getC16());
            dataList.append(data.getC26());
            dataList.append(data.getC36());
            dataList.append(data.getC46());
            dataList.append(data.getC56());
            dataList.append(data.getC66());
            dataList.append(data.getForM());
            dataList.append(data.getVorVR());
            dataList.append(data.getF1());
            dataList.append(data.getF2());
            dataList.append(data.getF3());
            dataList.append(data.getM1());
            dataList.append(data.getM2());
            dataList.append(data.getM3());
            dataList.append(data.getV1());
            dataList.append(data.getV2());
            dataList.append(data.getV3());
            dataList.append(data.getVR1());
            dataList.append(data.getVR2());
            dataList.append(data.getVR3());
            dataList.append(data.getCP1());
            dataList.append(data.getCP2());
            dataList.append(data.getCP3());
            dataList.append(data.getCPR1());
            dataList.append(data.getCPR2());
            dataList.append(data.getCPR3());
            dataList.append(data.getCCU1());
            dataList.append(data.getCCU2());
            dataList.append(data.getCCU3());
            dataList.append(data.getCCUR1());
            dataList.append(data.getCCUR2());
            dataList.append(data.getCCUR3());
            writeDoubleAttributeDataset(h5Group, std::to_string(i), dataList, 1, 47);
        }
        return true;
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::readBehaviorLock(Interface::FITKAbaConnectorBehavior* connectorBehavior, H5::Group & h5Group)
    {
        auto cb = dynamic_cast<Interface::FITKAbaConnectorBehaviorLock*>(connectorBehavior);
        if (!cb) return false;
        bool isValid = false;

        if (h5Group.attrExists("Components"))
        {
            H5::Attribute att = h5Group.openAttribute("Components");
            std::array<bool, 6> buf;
            att.read(H5::PredType::NATIVE_HBOOL, &buf);
            cb->setComponents(buf);
        }

        auto sLockType = readStrAttribute(h5Group, "LockType");
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::LockType> fitkLTypeTrafer;
        auto eLockType = fitkLTypeTrafer.fromString(QString::fromStdString(sLockType), isValid);
        if (!isValid) return false;
        cb->setLockType(eLockType);

        auto sLockSpecify = readStrAttribute(h5Group, "LockSpecify");
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::LockSpecify> fitkLSTypeTrafer;
        auto eLockSpecify = fitkLSTypeTrafer.fromString(QString::fromStdString(sLockSpecify), isValid);
        if (!isValid) return false;
        cb->setLockSpecify(eLockSpecify);

        double posCriteriaLower = readDoubleAttribute(h5Group, "PosCriteriaLower");
        cb->setPosCriteriaLower(posCriteriaLower);
        double posCriteriaUpper = readDoubleAttribute(h5Group, "PosCriteriaUpper");
        cb->setPosCriteriaUpper(posCriteriaUpper);
        double fMCriteriaLower = readDoubleAttribute(h5Group, "FMCriteriaLower");
        cb->setFMCriteriaLower(fMCriteriaLower);
        double fMCriteriaUpper = readDoubleAttribute(h5Group, "FMCriteriaUpper");
        cb->setFMCriteriaUpper(fMCriteriaUpper);

        bool usePosLower = readBoolAttribute(h5Group, "UsePosLower");
        cb->setUsePosLower(usePosLower);
        bool usePosUpper = readBoolAttribute(h5Group, "UsePosUpper");
        cb->setUsePosUpper(usePosUpper);
        bool useFMLower = readBoolAttribute(h5Group, "UseFMLower");
        cb->setUseFMLower(useFMLower);
        bool useFMUpper = readBoolAttribute(h5Group, "UseFMUpper");
        cb->setUseFMUpper(useFMUpper);
        return true;
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::writeBehaviorLock(Interface::FITKAbaConnectorBehavior* connectorBehavior, H5::Group & h5Group)
    {
        auto cb = dynamic_cast<Interface::FITKAbaConnectorBehaviorLock*>(connectorBehavior);
        if (!cb) return false;
        bool isValid = false;

        auto components = cb->getComponents();
        writeBoolAttribute(h5Group, "Components", &components, 1, 6);

        auto eLockType = cb->getLockType();
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::LockType> fitkLTypeTrafer;
        QString sLockType = fitkLTypeTrafer.toStrting(eLockType, isValid);
        if (!isValid) return false;
        writeStrAttribute(h5Group, "LockType", sLockType.toStdString());

        auto eLockSpecify = cb->getLockSpecify();
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::LockSpecify> fitkLSTypeTrafer;
        QString sLockSpecify = fitkLSTypeTrafer.toStrting(eLockSpecify, isValid);
        if (!isValid) return false;
        writeStrAttribute(h5Group, "LockSpecify", sLockSpecify.toStdString());
        double posCriteriaLower = cb->getPosCriteriaLower();
        writeDoubleAttribute(h5Group, "PosCriteriaLower", &posCriteriaLower);
        double posCriteriaUpper = cb->getPosCriteriaUpper();
        writeDoubleAttribute(h5Group, "PosCriteriaUpper", &posCriteriaUpper);
        double fMCriteriaLower = cb->getFMCriteriaLower();
        writeDoubleAttribute(h5Group, "FMCriteriaLower", &fMCriteriaLower);
        double fMCriteriaUpper = cb->getFMCriteriaUpper();
        writeDoubleAttribute(h5Group, "FMCriteriaUpper", &fMCriteriaUpper);

        bool usePosLower = cb->getUsePosLower();
        writeBoolAttribute(h5Group, "UsePosLower", &usePosLower);
        bool usePosUpper = cb->getUsePosUpper();
        writeBoolAttribute(h5Group, "UsePosUpper", &usePosUpper);
        bool useFMLower = cb->getUseFMLower();
        writeBoolAttribute(h5Group, "UseFMLower", &useFMLower);
        bool useFMUpper = cb->getUseFMUpper();
        writeBoolAttribute(h5Group, "UseFMUpper", &useFMUpper);

        return true;
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::readBehaviorPlasticity(Interface::FITKAbaConnectorBehavior* connectorBehavior, H5::Group & h5Group)
    {
        auto cb = dynamic_cast<Interface::FITKAbaConnectorBehaviorPlasticity*>(connectorBehavior);
        if (!cb) return false;
        bool isValid = false;


        auto sCoupling = readStrAttribute(h5Group, "Coupling");
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::Coupling> fitkCTypeTrafer;
        auto eCoupling = fitkCTypeTrafer.fromString(QString::fromStdString(sCoupling), isValid);
        if (!isValid) return false;
        cb->setCoupling(eCoupling);


        if (h5Group.attrExists("ForceMoment"))
        {
            H5::Attribute att = h5Group.openAttribute("ForceMoment");
            std::array<bool, 6> buf;
            att.read(H5::PredType::NATIVE_HBOOL, &buf);
            cb->setForceMoment(buf);
        }

        bool specifyHardening = readBoolAttribute(h5Group, "SpecifyHardening");
        cb->setSpecifyHardening(specifyHardening);
        bool specifyKinematicHardening = readBoolAttribute(h5Group, "specifyKinematicHardening");
        cb->setSpecifyKinematicHardening(specifyKinematicHardening);

        auto sIsoHardenDefinition = readStrAttribute(h5Group, "IsoHardenDefinition");
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::PlacticityIsoTropicHardeningDefinition> fitkPTHDTypeTrafer;
        auto eIsoHardenDefinition = fitkPTHDTypeTrafer.fromString(QString::fromStdString(sIsoHardenDefinition), isValid);
        if (!isValid) return false;
        cb->setIsoHardenDefinition(eIsoHardenDefinition);

        int isoHardenTabDataRowCount = readIntAttribute(h5Group, "IsoHardenTabDataRowCount");
        cb->setIsoHardenTabDataRowCount(isoHardenTabDataRowCount);

        for (int i = 0; i < isoHardenTabDataRowCount; ++i)
        {
            Interface::PlasticityIsoHardenTabData& data = cb->getIsoHardenTabDataRow(i);
            QList<double> dataList;

            if (readDoubleAttrbuteDataSet(h5Group, std::to_string(i), dataList, 1, 3))
            {
                Interface::PlasticityIsoHardenTabData& data = cb->getIsoHardenTabDataRow(i);
                data.setYieldForceMoment(dataList[0]);
                data.setPlasticMotion(dataList[1]);
                data.setRate(dataList[2]);
            }
        }
        return true;
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::writeBehaviorPlasticity(Interface::FITKAbaConnectorBehavior* connectorBehavior, H5::Group & h5Group)
    {
        auto cb = dynamic_cast<Interface::FITKAbaConnectorBehaviorPlasticity*>(connectorBehavior);
        if (!cb) return false;
        bool isValid = false;


        auto eCoupling = cb->getCoupling();
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::Coupling> fitkCTypeTrafer;
        QString sCoupling = fitkCTypeTrafer.toStrting(eCoupling, isValid);
        if (!isValid) return false;
        writeStrAttribute(h5Group, "Coupling", sCoupling.toStdString());

        auto forceMoment = cb->getForceMoment();
        writeBoolAttribute(h5Group, "ForceMoment", &forceMoment, 1, 6);

        bool specifyHardening = cb->getSpecifyHardening();
        writeBoolAttribute(h5Group, "SpecifyHardening", &specifyHardening);

        bool specifyKinematicHardening = cb->getSpecifyKinematicHardening();
        writeBoolAttribute(h5Group, "specifyKinematicHardening", &specifyKinematicHardening);

        auto eIsoHardenDefinition = cb->getIsoHardenDefinition();
        Core::FITKEnumTransfer<Interface::FITKAbaConnectorBehaviorEnum::PlacticityIsoTropicHardeningDefinition> fitkPTHDTypeTrafer;
        QString sIsoHardenDefinition = fitkPTHDTypeTrafer.toStrting(eIsoHardenDefinition, isValid);
        if (!isValid) return false;
        writeStrAttribute(h5Group, "IsoHardenDefinition", sIsoHardenDefinition.toStdString());
        int isoHardenTabDataRowCount = cb->getIsoHardenTabDataRowCount();
        writeIntAttribute(h5Group, "IsoHardenTabDataRowCount", &isoHardenTabDataRowCount);
        for (int i = 0; i < isoHardenTabDataRowCount; ++i)
        {
            Interface::PlasticityIsoHardenTabData& data = cb->getIsoHardenTabDataRow(i);
            QList<double> dataList;
            dataList.append(data.getYieldForceMoment());
            dataList.append(data.getPlasticMotion());
            dataList.append(data.getRate());
            writeDoubleAttributeDataset(h5Group, std::to_string(i), dataList, 1, 3);
        }
        return true;
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::readBehaviorStop(Interface::FITKAbaConnectorBehavior* connectorBehavior, H5::Group & h5Group)
    {
        auto cb = dynamic_cast<Interface::FITKAbaConnectorBehaviorStop*>(connectorBehavior);
        if (!cb) return false;
        bool isValid = false;

        if (h5Group.attrExists("Components"))
        {
            H5::Attribute att = h5Group.openAttribute("Components");
            std::array<bool, 6> buf;
            att.read(H5::PredType::NATIVE_HBOOL, &buf);
            cb->setComponents(buf);
        }
        double lowerBound = readDoubleAttribute(h5Group, "LowerBound");
        cb->setLowerBound(lowerBound);
        double upperBound = readDoubleAttribute(h5Group, "UpperBound");
        cb->setUpperBound(upperBound);
        return true;
    }

    bool FITKAbaqusHDF5AdaptorConnectorSection::writeBehaviorStop(Interface::FITKAbaConnectorBehavior* connectorBehavior, H5::Group & h5Group)
    {
        auto cb = dynamic_cast<Interface::FITKAbaConnectorBehaviorStop*>(connectorBehavior);
        if (!cb) return false;
        bool isValid = false;
        auto components = cb->getComponents();
        writeBoolAttribute(h5Group, "Components", &components, 1, 6);

        double lowerBound = cb->getLowerBound();
        writeDoubleAttribute(h5Group, "LowerBound", &lowerBound);
        double upperBound = cb->getUpperBound();
        writeDoubleAttribute(h5Group, "UpperBound", &upperBound);
        return true;
    }

}


